/**
 @ClassName:graphCfg
 @Author:TwT
 @Date:2022/5/27 20:37
 @Version:1.0
 **/
import {Graph, Shape} from '@antv/x6'
//边
Graph.registerEdge(
    'custom-edge',
    {
        inherit: 'edge',
        defaultLabel: {
            markup: [
                {
                    tagName: 'rect',
                    selector: 'body',
                },
                {
                    tagName: 'text',
                    selector: 'label',
                },
            ],
            attrs: {
                label: {
                    fill: '#000',
                    fontSize: 14,
                    textAnchor: 'middle',
                    textVerticalAnchor: 'middle',
                    pointerEvents: 'none',
                },
                body: {
                    ref: 'label',
                    fill: '#ffd591',
                    stroke: '#ffa940',
                    strokeWidth: 2,
                    rx: 4,
                    ry: 4,
                    refWidth: '140%',
                    refHeight: '140%',
                    refX: '-20%',
                    refY: '-20%',
                },
            },
            position: {
                distance: 200,
                options: {
                    absoluteDistance: true,
                    reverseDistance: true,
                },
            },
        },
    },
    true,
)

export const graphCfg = {
    //网格线
    grid: {
        visible: true
    },
    //画布拖拽
    panning: {
        enabled: true,
        //按住shift可拖拽
        // modifiers: 'shift',
        eventTypes: ['leftMouseDown']
    },
    //滚轮缩放
    mousewheel: {
        enabled: true,
        zoomAtMousePosition: true,
        modifiers: 'ctrl',
        minScale: 0.5,
        maxScale: 3,
    },


    //节点连线
    connecting: {
        router: {
            name: 'manhattan',
            args: {
                padding: 1,
            },
        },
        connector: {
            name: 'rounded',
            args: {
                radius: 8,
            },
        },
        anchor: 'center',
        connectionPoint: 'anchor',
        allowBlank: false,
        snap: {
            radius: 20,
        },
        createEdge() {
            return new Shape.Edge({
                shape: 'custom-edge',
                /*attrs: {
                    line: {
                        stroke: '#A2B1C3',
                        strokeWidth: 2,
                        targetMarker: {
                            name: 'block',
                            width: 12,
                            height: 8,
                        },
                    },
                    label: { text: 'edge' }
                },
                zIndex: 0,*/
            })
        },
        validateConnection({targetMagnet}) {
            return !!targetMagnet
        },
    },
    highlighting: {
        magnetAdsorbed: {
            name: 'stroke',
            args: {
                attrs: {
                    fill: '#5F95FF',
                    stroke: '#5F95FF',
                },
            },
        },
    },


    //节点拉伸
    // resizing: true,
    //节点旋转
    // rotating: true,
    //节点选中
    selecting: {
        // enabled: true,
        rubberband: true,
        showNodeSelectionBox: true,
    },
    //对齐线
    snapline: true,
    keyboard: true,
    clipboard: true,

}